package com.example.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.entity.User;
import com.example.demo.mapper.UserMapper;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

/**
 * <p>Description:</p>
 * <p>Copyright: Copyright (c) 2017</p>
 *
 * @author gaol
 * @version 1.0
 * @date 2017/6/5
 */
@RestController
@RequestMapping(value = "/user")
public class UserController {

    /**
     *
     */
    @Autowired
    private UserMapper userMapper;

    @ApiOperation(value="test1",notes="1111111")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "开始时间", paramType = "query", dataType = "String"),
    @ApiImplicitParam(name = "id1", value = "开始时间1111", paramType = "path", dataType = "Long")})
    @GetMapping(value = "/{id}")
    public User getUser(@PathVariable("id") Long id) {
        return userMapper.select(id);
    }

    @PostMapping(value = "/add")
    public int addUser(String name, String password) {
        User user = new User();
        user.setPassword(password);
        user.setName(name);
        return userMapper.insert(user);
    }

    @PutMapping(value = "/update")
    public int update(String name){
        User user = new User();
        user.setName(name);
        user.setPassword("654321");
        return userMapper.update(user);
    }

    @PostMapping(value = "/delete")
    public int delete(Long id){
        return userMapper.delete(id);
    }

}
